package com.yyk.yykywd.ui.login

import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer
import com.gyf.immersionbar.ktx.immersionBar
import com.orhanobut.hawk.Hawk
import com.yyk.yykywd.PRIVACY_POLICY
import com.yyk.yykywd.R
import com.yyk.yykywd.USER_AGREEMENT
import com.yyk.yykywd.base.NewBaseActivity
import com.yyk.yykywd.databinding.ActivityLoginBinding
import com.yyk.yykywd.getViewModel
import com.yyk.yykywd.listenter.DialogSureCancelListenter
import com.yyk.yykywd.ui.MainActivity
import com.yyk.yykywd.util.DialogUtil
import com.yyk.yykywd.util.ToAnotherActivity.toAgreementActivity
import com.yyk.yykywd.util.ToAnotherActivity.toCommonActivity
import com.yyk.yykywd.util.ToastUtil
import com.yyk.yykywd.util.setTextClick
import com.yyk.yykywd.util.setTextForegroundColor
import kotlinx.android.synthetic.main.activity_login.*

class LoginActivity : NewBaseActivity() {
    private val viewModel by lazy {
        getViewModel(this, LoginViewModel::class.java)
    }

    override fun initView() {
        Hawk.put("ISLOGFLAG", TAG)
        val binding : ActivityLoginBinding =  DataBindingUtil.setContentView(this,R.layout.activity_login)
        binding.viewModel = viewModel
        binding.lifecycleOwner = this

        viewModel.loginInfo.observe(this, Observer {
            when (it.code) {
                200 -> {
                    ToastUtil.showShort(it.msg)
                    toCommonActivity(mActivity,MainActivity::class.java)
                    finish()
                }
                306 -> {
                    DialogUtil.showReturnTips(mActivity, "", "手机号不存在目前仅限于云医康内部员工使用", "好的", "", object : DialogSureCancelListenter {
                        override fun onSureListenter() {}
                        override fun onCancelListenter() {}
                    }, true)
                }
                else -> {
                    ToastUtil.showShort(it.msg)
                }
            }
        })

        setTextForegroundColor(mActivity, tv_hint, "仅供企业内部员工", "云医康业务版 仅供企业内部员工 使用")
        setTextForegroundColor(mActivity, tv_user_agreement, "《用户服务协议》", "登录即代表您同意云医康《用户服务协议》和")
        setTextForegroundColor(mActivity, tv_privacy_policy, "《隐私协议》", "《隐私协议》")
        setTextClick(mActivity, tv_user_agreement, "《用户服务协议》", "登录即代表您同意云医康《用户服务协议》和") {
            toAgreementActivity(mActivity, USER_AGREEMENT)
        }
        setTextClick(mActivity, tv_privacy_policy, "《隐私协议》", "《隐私协议》") {
            toAgreementActivity(mActivity, PRIVACY_POLICY)
        }
    }

    override fun initImmersionBar() {
        immersionBar {}
    }

    companion object {
        const val TAG = "LoginActivity"
    }
}